<?php

// 接收前端传过来的参数
$name=$_POST['name'];
$pwd=$_POST['pwd'];

$conn = mysqli_connect('localhost', 'root', 'root', '2006');
mysqli_query($conn, "set charset 'utf8'");
mysqli_query($conn, "set character set 'utf8'");


$sql="select * from users where name='$name' and pwd='$pwd'";

$res=mysqli_query($conn,$sql);

$len=mysqli_num_rows($res);
if($len>0){
  echo json_encode(array(
    "code" => 200,
    "body" => array(
      "msg" => "登陆成功,返回首页"
    )
  ));
} else {
  echo json_encode(array(
    "code" => 201,
    "body" => array(
      "msg" => "账户名或密码错误,请重试"
    )
  ));
}
?>